package async;

import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;

public class ThenAcceptDemo {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(100);
        CompletableFuture.supplyAsync(() -> {
            int value = new Random().nextInt(100);
            System.out.println(value);
            return value;
        }).thenAcceptAsync(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println("接收上一个任务结果为：" + integer);
            }
        }, executor);
        executor.shutdown();
    }
}
